<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>钻石投票_选手管理</title>
    <link rel="stylesheet" href="__MCSS__/bass.css">
    <link rel="stylesheet" href="__CSS__/font-awesome.css">
    <link rel="stylesheet" href="__JS__/layui/css/layui.css">
    <link rel="stylesheet" href="__MCSS__/layui-pageadd.css">
    <link rel="stylesheet" href="__MCSS__/layui-add.css">
    <link rel="stylesheet" href="__MCSS__/public.css"/>
    <link rel="stylesheet" href="__MCSS__/palyer_run.css">
</head>
<body>

<div class="palyer-run">

    <div class="palyer-body">

        <!-- 面包屑 -->
        <p class="bread-crumbs-nav"><span class="span1">微活动</span><i class="fa fa-caret-right"></i><span class="span2">选手管理</span></p>

        <p class="palyer-name">男神女神自拍大赛</p>

        <!--内容区-->
        <div class="palyer-main">
            <div class="palyer-all">
                <div class="palyer-all-list {if condition='$config.is_audit == -1'}palyer-active{/if}" data-type="-1">全部选手</div>
                <div class="palyer-all-list {if condition='$config.is_audit == 0'}palyer-active{/if}" data-type="0">待审核</div>
                <div class="palyer-all-list {if condition='$config.is_audit == 1'}palyer-active{/if}" data-type="1">已审核</div>
                <div class="player-head-btn">
                    <p class="time_text" ><i class="fa fa-clock-o" aria-hidden="true"></i>00时00分00秒</p>
                    <input type="hidden" value="{$config.time}" id="time">
                </div>
            </div>


            <div class="palyer-tit">
                <!-- 搜索 -->
                <div class="palyer-tit-seach">
                    <p><input type="text" placeholder="搜索选手编号/昵称"></p>
                    <span>搜索</span>
                </div>

                <!-- 功能按钮 -->
                <div class="palyer-tit-btn">
                    <ul>
                        <a href="/admin/competitor/add"><li class="palyer-tit-li"><i class="fa fa-plus" aria-hidden="true"></i>添加选手</li></a>
                        <li class="palyer-tit-li"><i class="fa fa-plus" aria-hidden="true"></i>批量添加</li>
                        <a href="/admin/competitor/exportExcel?activity_id={$config.activity_id}"><li class="palyer-tit-li"><i class="fa fa-upload" aria-hidden="true"></i>导出排名</li></a>
                        <li class="palyer-tit-li"><i class="fa fa-download" aria-hidden="true"></i>批量导入</li>
                        <li class="palyer-tit-li more-del" data-type="isdelete" data-value="1"><i class="fa fa-trash" aria-hidden="true"></i>批量删除</li>
                        <li class="palyer-tit-li more-del" data-type="remark" data-value="1"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>批量备注</li>
                        <li class="palyer-tit-li plusticket" data-type="ticket"><i class="fa fa-plus" aria-hidden="true"></i>一键全局加票</li>
                        <li class="palyer-tit-li plusticket" data-type="browse"><i class="fa fa-plus" aria-hidden="true"></i>一键加浏览量</li>
                        <li class="palyer-tit-li plusticket2"><i class="fa fa-plus" aria-hidden="true"></i>当页手动加票</li>
                        <li class="palyer-tit-li"><i class="fa fa-plus" aria-hidden="true"></i>自动投票</li>
                        <li class="palyer-tit-li"><i class="fa fa-plus" aria-hidden="true"></i>自动礼物</li>
                        <li class="palyer-tit-li palyer-warning" onclick="$('.palyer-li-input').val(0)"><i class="fa fa-trash" aria-hidden="true"></i>清空</li>
                    </ul>
                </div>
            </div>
            <!-- 数据列表 -->
            <div class="palyer-table">
                <div class="palyer-table-container">
                    <div class="palyer-table-tit">
                        <ul>
                            <li class="palyer-tit-li1">
                                <div class="palyer-tit-check"><i class="fa fa-check"></i></div>
                            </li>
                            <li class="palyer-tit-li2">
                                <span class="span1 {if condition="$config.order_type=='competitor_num'"}color1{/if}  addblock">选手编号</span>

                                <span class="span5 {if condition="$config.order_type=='competitor_num'"}color1{/if} addblock"><i class="fa {if condition="$config.order_type=='competitor_num' && $config.order_value=='asc'"}fa-long-arrow-up{else /}fa-long-arrow-down{/if} order" data-type="competitor_num"></i></span>
                            </li>
                            <li class="palyer-tit-li3"><span>手机号码</span></li>
                            <li class="palyer-tit-li4">
                                <span class="span1 {if condition="$config.order_type=='day_ticket_num'"}color1{/if} addblock">今</span>
                                <span class="span2">/</span>
                                <span class="span3 {if condition="$config.order_type=='sum_ticket_num'"}color1{/if} addblock">总</span>
                                <span class="span4">票数</span>
                                <span class="span5 {if condition="$config.order_type=='day_ticket_num'"}color1{/if} addblock"><i class="fa {if condition="$config.order_type=='day_ticket_num' && $config.order_value=='asc'"}fa-long-arrow-up{else /}fa-long-arrow-down{/if} order" data-type="day_ticket_num"></i></span>
                                <span class="span6 {if condition="$config.order_type=='sum_ticket_num'"}color1{/if} addblock"><i class="fa {if condition="$config.order_type=='sum_ticket_num' && $config.order_value=='asc'"}fa-long-arrow-up{else /}fa-long-arrow-down{/if} order" data-type="sum_ticket_num"></i></span>
                            </li>
                            <li class="palyer-tit-li5">
                                <span class="span1 {if condition="$config.order_type=='day_money_num'"}color1{/if} addblock">今</span>
                                <span class="span2">/</span>
                                <span class="span3 {if condition="$config.order_type=='sum_money_num'"}color1{/if} addblock">总</span>
                                <span class="span4">礼物</span>
                                <span class="span5 {if condition="$config.order_type=='day_money_num'"}color1{/if} addblock"><i class="fa {if condition="$config.order_type=='day_money_num' && $config.order_value=='asc'"}fa-long-arrow-up{else /}fa-long-arrow-down{/if} order" data-type="day_money_num"></i></span>
                                <span class="span6 {if condition="$config.order_type=='sum_money_num'"}color1{/if} addblock"><i class="fa {if condition="$config.order_type=='sum_money_num' && $config.order_value=='asc'"}fa-long-arrow-up{else /}fa-long-arrow-down{/if} order" data-type="sum_money_num"></i></span>
                            </li>
                            <li class="palyer-tit-li6">
                                <span class="span1 {if condition="$config.order_type=='day_browse_num'"}color1{/if} addblock">今</span>
                                <span class="span2">/</span>
                                <span class="span3 {if condition="$config.order_type=='sum_browse_num'"}color1{/if} addblock">总</span>
                                <span class="span4">浏览</span>
                                <span class="span5 {if condition="$config.order_type=='day_browse_num'"}color1{/if} addblock"><i class="fa {if condition="$config.order_type=='day_browse_num' && $config.order_value=='asc'"}fa-long-arrow-up{else /}fa-long-arrow-down{/if} order" data-type="day_browse_num"></i></span>
                                <span class="span6 {if condition="$config.order_type=='sum_browse_num'"}color1{/if} addblock"><i class="fa {if condition="$config.order_type=='sum_browse_num' && $config.order_value=='asc'"}fa-long-arrow-up{else /}fa-long-arrow-down{/if} order" data-type="sum_browse_num"></i></span>
                            </li>
                            <li class="palyer-tit-li7">
                                <span class="span1 {if condition="$config.order_type=='create_time'"}color1{/if} addblock">参与时间</span>
                                <span class="span5 {if condition="$config.order_type=='create_time'"}color1{/if} addblock"><i class="fa {if condition="$config.order_type=='create_time' && $config.order_value=='asc'"}fa-long-arrow-up{else /}fa-long-arrow-down{/if} order" data-type="create_time"></i></span>
                            </li>
                            <li class="palyer-tit-li8"><span>状态</span></li>
                            <li class="palyer-tit-li9"><span>操作</span></li>
                            <li class="palyer-tit-li10"><span>备注</span></li>
                        </ul>
                    </div>
                    <div class="palyer-table-body">
                        {notempty name="com_array"}
                        {volist name="com_array" id="node"}
                        <ul class="palyer-table-ul" data-id="{$node.id}">
                            <li class="palyer-tit-li1">
                                <div class="palyer-table-check"><i class="fa fa-check"></i></div>
                            </li>
                            <li class="palyer-tit-li2"><img src="{$node.first_image}" alt="">0{$node.competitor_num}/{$node.name}</a></li>
                            <li class="palyer-tit-li3">{$node.tel}</li>
                            <li class="palyer-tit-li4">
                                <p class="palyer-li-p bg1">今：{$node.day_ticket_num}</p>
                                <p class="palyer-li-p">实：{$node.ticket_num}</p>
                                <p class="palyer-li-p">总：<span>{$node.sum_ticket_num}</span></p>
                                <p><input class="palyer-li-input" type="text" placeholder="" value="0"><span class="palyer-li-btn" data-type="ticket">加</span></p>
                            </li>
                            <li class="palyer-tit-li5">
                                <p class="palyer-li-p bg2">今：{$node.day_money_num}</p>
                                <p class="palyer-li-p">实：{$node.money_num}</p>
                                <p class="palyer-li-p">总：<span>{$node.sum_money_num}</span></p>
                                <p><input class="palyer-li-input" type="text" placeholder="" value="0"><span class="palyer-li-btn" data-type="money">加</span></p>
                            </li>
                            <li class="palyer-tit-li6">
                                <p class="palyer-li-p bg1">今：{$node.day_browse_num}</p>
                                <p class="palyer-li-p">实：{$node.browse_num}</p>
                                <p class="palyer-li-p">总：<span>{$node.sum_browse_num}</span></p>
                                <p><input class="palyer-li-input" type="text" placeholder="" value="0"><span class="palyer-li-btn" data-type="browse">加</span></p>
                            </li>
                            <li class="palyer-tit-li7"><p>{:date("Y-m-d H:i:s",$node.create_time)}</p></li>
                            <li class="palyer-tit-li8">
                                <div class="palyer-body-p">
                                    {if condition="$node.is_audit == 1"}
                                    <p data-type="is_audit" data-value="0">已审核</p>
                                    <p data-type="is_audit" data-value="1" class="palyer-none palyer-warning">待审核</p>
                                    {else /}
                                    <p data-type="is_audit" data-value="0" style="display: none;">已审核</p>
                                    <p data-type="is_audit" data-value="1" class="palyer-warning">待审核</p>
                                    {/if}
                                </div>
                                <div class="palyer-body-p">
                                    {if condition="$node.is_lock == 0 || time() > (int)$node.lock_time"}
                                    <p data-type="is_lock" data-value="1" style="margin: 2px 0px;">无锁定</p>
                                    <p data-type="is_lock" data-value="0" style="margin: 2px 0px;" class="palyer-none palyer-warning" title="点击解锁(恢复时间{:date('Y-m-d H:i:s',(int)$node.lock_time)})">已锁定</p>
                                    {else /}
                                    <p data-type="is_lock" data-value="1" style="margin: 2px 0px;display: none;">无锁定</p>
                                    <p data-type="is_lock" data-value="0" style="margin: 2px 0px;" class="palyer-warning" title="点击解锁(恢复时间{:date('Y-m-d H:i:s',(int)$node.lock_time)})">已锁定</p>
                                    {/if}
                                </div>
                            </li>
                            <li class="palyer-tit-li9">
                                <div class="palyer-tit-container">
                                    <div class="palyer-body-btn"><i class="fa fa-link" aria-hidden="true"></i>选手链接</div>
                                    <div class="palyer-body-btn"><i class="fa fa-server"></i>数据记录</div>
                                    <div class="palyer-body-btn star-of-today" data-activi_id="{$node.activity_id}"><i class="fa fa-star-o" aria-hidden="true"></i>今日之星</div>
                                    <div class="palyer-body-btn"><i class="fa fa-pencil" aria-hidden="true"></i>修改</div>
                                    <div class="palyer-body-btn del-competitor"><i class="fa fa-trash" aria-hidden="true"></i>删除</div>
                                    <div class="palyer-body-btn palyer-btn-more">
                                        <i class="fa fa-caret-square-o-down" aria-hidden="true"></i>更多
                                        <div class="palyer-more-btn palyer-none boxs1">
                                            <div class="palyer-ticket-btn">
                                                <div class="palyer-more-msg">允许投票：</div>
                                                <div class="palyer-ticket-on">
                                                    <form class="layui-form" action="">
                                                        <div class="layui-form-item">
                                                            <div class="layui-input-block">
                                                                <input type="checkbox" name="ticket" data-type="is_vote" lay-skin="switch" lay-text="启用|停用" {if condition="$node.is_vote == 0"}checked{/if}>
                                                            </div>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                            <div class="palyer-git-btn">
                                                <div class="palyer-more-msg">允许礼物：</div>
                                                <div class="palyer-gift-on">
                                                    <form class="layui-form" action="">
                                                        <div class="layui-form-item">
                                                            <div class="layui-input-block">
                                                                <input type="checkbox" name="yyy" data-type="is_money" lay-skin="switch" lay-text="启用|停用" {if condition="$node.is_money == 0"}checked{/if}>
                                                            </div>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <li class="palyer-tit-li10"><p>{$node.remark}</p></li>
                        </ul>
                        {/volist}
                        {/notempty}


                    </div>
                </div>
            </div>

            <div class="palyer-page"><div id="palyer-page-list"></div></div>
            {$com_array|raw}
        </div>
    </div>
</div>

</body>

<script src="__JS__/jquery_v3.3.1.js"></script>
<script src="__JS__/layer/layer.js"></script>
<script src="__JS__/layui/layui.js"></script>
<script src="__JS__/common.js"></script>

<script type="text/javascript">

    //活动倒计时
    var time_obj = $("#time");
    setInterval(function () {
        time_obj.val(time_obj.val() - 1);
        var second = time_obj.val();
        var time = dateFormat(second);
        $(".time_text").html('<i class="fa fa-clock-o" aria-hidden="true"></i>' + time);
    }, 1000);

    // 顶部切换选项
    $('.palyer-all-list').click(function () {
        $('.palyer-all-list').removeClass('palyer-active');
        $(this).addClass('palyer-active').siblings().removeClass('palyer-active');
        var type = $(this).data("type");
        location.href = '/admin/competitor/index?is_audit=' + type;
    });

    //顶部单选按钮
    $('.palyer-tit-check').click(function () {
        if ($(this).hasClass('bg3')) {
            $(this).removeClass('bg3');
            $('.palyer-table-check').removeClass('bg3');
            return false;
        }
        $(this).addClass('bg3');
        $('.palyer-table-check').addClass('bg3');
    });
    //列表单选按钮
    $('.palyer-table-check').click(function () {
        if ($(this).hasClass('bg3')) {
            $(this).removeClass('bg3');
            return false;
        }
        $(this).addClass('bg3');
    });
    //第一个排序箭头
    $('.palyer-table-tit ul li .span5').on('click', function () {

        var Chid = $(this).children();
        // 清除·原有颜色
        $('.addblock').removeClass('color1');
        //图标都设为向下样式
        $(this).removeClass('addblock');
        $('.addblock').children().removeClass('fa-long-arrow-up').addClass('fa-long-arrow-down');

        //改变图标样式
        if (Chid.hasClass('fa-long-arrow-down')) {
            Chid.removeClass('fa-long-arrow-down').addClass('fa-long-arrow-up');
        } else {
            Chid.removeClass('fa-long-arrow-up').addClass('fa-long-arrow-down');
        }
        //最终显示
        $(this).parent().find('.span1').addClass('color1');
        $(this).addClass('color1 addblock');

    });
    //第二个顺序箭头
    $('.palyer-table-tit ul li .span6').on('click', function () {

        var Chid = $(this).children();
        // 清除·原有颜色
        $('.addblock').removeClass('color1');
        //图标都设为向下样式
        $(this).removeClass('addblock');
        $('.addblock').children().removeClass('fa-long-arrow-up').addClass('fa-long-arrow-down');
        //改变图标样式
        if (Chid.hasClass('fa-long-arrow-down')) {
            Chid.removeClass('fa-long-arrow-down').addClass('fa-long-arrow-up');
        } else {
            Chid.removeClass('fa-long-arrow-up').addClass('fa-long-arrow-down');
        }
        //最终显示
        $(this).parent().find('.span3').addClass('color1');
        $(this).addClass('color1 addblock');
    });


    //点击切换操作状态
    $('.palyer-body-p').click(function () {
        $(this).find('p').toggle();
    });

    //点更多按钮显示隐藏内容
    $('.palyer-btn-more').click(function () {
        //判断当前点击的更多内容是否已经显示，若显示隐藏
        if ($(this).find('.palyer-more-btn').css('display') == 'block') {
            $(this).find('.palyer-more-btn').hide();
            return false;
        }
        // 所有更多内容都不显示
        $('.palyer-more-btn').hide();
        // 当前点击的内容显示
        $(this).find('.palyer-more-btn').show();
        return false;
    });

    //点击更多按钮以外隐藏更多选项
    $('body').click(function () {
        $('.palyer-more-btn').hide();
    });
    //取消点击更多下开关的冒泡时间
    $('.palyer-more-btn').click(function () {
        return false;
    });

    //切换开关
    layui.use('form', function () {
        var form = layui.form;
        //监听指定开关
        form.on('switch', function (data) {
            var obj = $(this);
            var id = obj.parents(".palyer-table-ul").data("id");
            var field = obj.data("type"), value;
            if (this.checked == true) {
                value = 0;
            } else {
                value = 1;
            }
            $.post("/admin/competitor/editCompetitor", {"field": field, "value": value, "id": id}, function (result) {
                if (result) {
                    layer.msg("设置成功");
                } else {
                    layer.msg("设置失败");
                }
            });
        });
    });


    //分页设置
    layui.use('laypage', function () {
        var laypage = layui.laypage;

        laypage.render({
            elem: 'palyer-page-list', //注意，这里的 test1 是 ID，不用加 # 号
            count: 80, //数据总数，从服务端得到
            layout: ['count', 'prev', 'page', 'next', 'skip'],
            groups: 4,
            limit: 20,
            jump: function (obj, first) {
                //obj包含了当前分页的所有参数，比如：
                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                console.log(obj.limit); //得到每页显示的条数
            }
        });
    });

    $(document).on("click", ".palyer-li-btn", function () {
        var obj = $(this);
        var type = obj.data("type");
        var id = obj.parents(".palyer-table-ul").data("id");
        var num = obj.prev().val();
        $.post("/admin/competitor/incr", {"field": type, "value": num, "id": id}, function (result) {
            if (result) {
                layer.msg("修改成功");
                var span = obj.parent().prev().children("span");
                span.html(parseInt(span.html()) + parseInt(num));
            } else {
                layer.msg("修改失败，请稍后再试");
            }
        });
    });

    $(document).on("click", ".palyer-body-p > p", function () {
        var obj = $(this),
         id = obj.parents(".palyer-table-ul").data("id"),
         field = obj.data("type"),
         value = obj.data("value"),
         val;
        if (field === "is_lock" && value === 1) {
            if (val = prompt("请输入锁定分钟数:",30)) {
                value = val;
            } else {
                return false;
            }
        }
        $.post("/admin/competitor/editCompetitor", {"field": field, "value": value, "id": id}, function (result) {
            if (result) {
                location.reload();
            } else {
                layer.msg("设置失败");
            }
        });

    });


    $(".palyer-li-input").on("keydown", function (ev) {
        if (ev.keyCode == 13) {
            $(this).next().next();
        }
    });

    //排序
    $(document).on("click",".order",function () {
            var type = $(this).data("type");
            var is_audit = $(".palyer-active").data("type");
            var order_value = "desc";
            if ($(this).hasClass("fa-long-arrow-up")) {
                order_value = 'asc';
            }
            location.href="/admin/competitor/index?order_type="+type+"&is_audit="+is_audit+"&order_value="+order_value;
    });

    //今日之星
    $(document).on("click", ".star-of-today", function () {
        var activi_id = $(this).data("activi_id");
        var competitor_id = $(this).parents("ul").data("id");
        $.post("/admin/competitor/setactivi", {'activi_id': activi_id, 'competitor_id': competitor_id}, function (result) {
            if (result) {
                layer.msg("设置成功");
            } else {
                layer.msg("设置失败");
            }
        });
    });

    //删除选手
    $(document).on("click", ".del-competitor", function () {
        var obj = $(this);
        var id = obj.parents("ul").data("id");
        $.post("/admin/competitor/editCompetitor", {"id":id,"field":"isdelete","value":1}, function (result) {
            if (result) {
                obj.parents("ul").remove();
                layer.msg("删除成功");
            } else {
                layer.msg("删除失败");
            }
        });
    });

    //批量删除
    $(document).on("click", '.more-del', function () {
        var checkObj = $(".palyer-table-ul .bg3");
        if (checkObj.length < 1) {
            layer.msg("请选择选手");
            return false;
        }
        var field = $(this).data("type");
        var value = $(this).data("value");
        if(field == 'remark'){
          var value = prompt("请输入备注名");
          if(!value){
              return false;
          }
          console.log(value);
        }
        var ids = '';
        $.each(checkObj, function (k, node) {
            var id = $(node).parents(".palyer-table-ul").data("id");
            ids += "," + id;
        });
        $.post("/admin/competitor/editData", {"ids": ids,'field':field,"value":value}, function (result) {
            if (result) {
                location.reload();
            } else {
                layer.msg("操作失败");
            }
        });
    });

    //一键全局加票
    $(document).on("click", ".plusticket", function () {
        var type = $(this).data("type");
        $.post("/admin/competitor/plusticket", {"type":type,"min": 1, "max": 30, "activity_id": 11}, function (result) {
            if (result) {
                layer.msg("修改成功");
                setTimeout(function () {
                    location.reload();
                }, 1000);
            } else {
                layer.msg("修改失败");
            }
        });
    });
    
    //当页手动加票
    $(document).on("click",".plusticket2",function () {
        var checkObj = $(".palyer-table-ul .bg3");
        if (checkObj.length < 1) {
            checkObj = $(".palyer-table-ul .palyer-table-check");
        }
        var ids = [];
        $.each(checkObj, function (k, node) {
            var id = $(node).parents(".palyer-table-ul").data("id");
            var val = $(node).parents(".palyer-table-ul").find(".palyer-li-btn[data-type=ticket]").prev().val();
            if (val && val != 0) {
                ids[id] = val;
            }
        });
        if (!ids || ids.length == 0) {
            layer.msg("请填写加票值");
            return false;
        }
        $.post("/admin/competitor/plusPageTicket", {"ids": ids}, function (result) {
            if (result) {
                location.reload();
            } else {
                layer.msg("操作失败");
            }
        });
    });

    //回车键触发加票
    $(document).on("keydown", ".palyer-li-input", function (ev) {
        if (ev.keyCode == 13) {
            $(this).next().click();
        }
    });
    //shift + key 触发当页手动加票
    $(document).on("keydown", function (ev) {
        if (ev.keyCode === 13 && ev.shiftKey === true) {
            $(".plusticket2").click();
        }
    });

    // $(function () {
    //     var palyer = localStorage.getItem("palyer{$config.activity_id}");
    //     palyer = $.parseJSON(palyer);
    //     console.log(palyer);
    //     $.each(palyer,function (k,val) {
    //         // console.log(val);
    //         $.each(val,function (key,node) {
    //             console.log(".palyer-table-ul[data-type="+k+"] .palyer-li-input:eq("+key+")")
    //             // $(".palyer-table-ul[data-type="+k+"] .palyer-li-input:eq("+key+")").val(node);
    //         });
    //     });
    // });
    //
    // //页面离开事件
    // window.onbeforeunload = function (ev) {
    //     var json = {};
    //     $.each($(".palyer-table-ul"),function (k,val) {
    //         var obj =  $(val).find(".palyer-li-input");
    //         var id =  $(val).data("id");
    //         json[id] = [];
    //         $.each(obj,function (key,node) {
    //             json[id][key] = node.value;
    //         });
    //     });
    //     var str = JSON.stringify(json);
    //     localStorage.setItem("palyer{$config.activity_id}",str);
    //     return false;
    // }

</script>

</html>